package com.zhuang.thread.waiting;

public class WaitingTest {

	private static Object object = new Object();

	public static void main(String[] args) throws InterruptedException {
		Thread t1 = new Thread() {
			@Override
			public void run() {
				synchronized (object) {
					System.out.println("调用wait方法，当前线程进入无限等待 。。。等着别的线程来唤醒");
					try {
						object.wait();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("唤醒这个线程，就不是无限等待了，线程执行完毕");
				}
			}
		};
		t1.start();

		new Thread() {
			public void run() {
				synchronized (object) {
					try {
						Thread.sleep(3000);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
					System.out.println("获取到锁的唤醒动作");
					object.notify();
				}
			}
		}.start();
		Thread.sleep(3000);
		System.out.println("查看t1的线程状态" + t1.getState());
	}
}
